package com.changcheng.service.Imp;

import com.changcheng.mapper.CarouselMapMapper;
import com.changcheng.pojo.CarouselMap;
import com.changcheng.service.CarouselMapService;
import com.changcheng.utils.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class CarouselMapServiceImp implements CarouselMapService {
    @Autowired
    private CarouselMapMapper carouselMapMapper;

    @Override
    public void addCarouselMap(CarouselMap carouselMap) {
        carouselMapMapper.addCarouselMap(carouselMap);
    }

    @Override
    public boolean deleteCarouselMap(Integer id) {
        //查询最大id
        int max_id = carouselMapMapper.selectMaxID();
        carouselMapMapper.deleteCarouselMap(id);
        if(!carouselMapMapper.deleteCarouselMap(id)){
            //删除一条数据，下面的id自动往上顶
            carouselMapMapper.deleteCarouselMap_chongpai(id);
            //删除最后一条数据，以后添加数据从上一条数据自增1
            if (id == max_id){
                carouselMapMapper.updateAUTO_INCREMENT();
            }
        }
        return true;
    }

    @Override
    public void updateCarouselMapStatus(CarouselMap carouselMap) {
        if (carouselMap.getStatus() == "01")
        {
            carouselMap.setStatus("02");
        }if(carouselMap.getStatus() == "02"){
            carouselMap.setStatus("01");
        }
        carouselMapMapper.updateCarouselMapStatus(carouselMap);
    }

    @Override
    public List<CarouselMap> select(CarouselMap carouselMap) {
        List<CarouselMap> select =  carouselMapMapper.select(carouselMap);
        return select;
    }
}
